package com.lovo.psc.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitConfig {

    @Autowired
    CachingConnectionFactory connectionFactory;
    //rabbitmq模板
    @Bean(value = "rabbitTemplate")
    public RabbitTemplate rabbitTemplate(){
        return new RabbitTemplate(connectionFactory);
    }
    //创建队列
    //供应商注册队列
    @Bean
    public Queue queuePscHjh(){
        return new Queue("queuePscHjh");
    }
    //创建交换机
    @Bean
    public DirectExchange directExchangeHjh(){
        return new DirectExchange("directExchangeHjh");
    }
    //交换机与队列绑定
    @Bean
    public Binding directExchangeToQueueOne(Queue queuePscHjh,DirectExchange directExchangeHjh){
        return BindingBuilder.bind(queuePscHjh).to(directExchangeHjh).with("Hjh.key");
    }


    //供应商供货订单
    @Bean(name = "queueTwo")
    public Queue queueTwo(){
        return new Queue("queuePscOrder");
    }
    //创建交换机
    @Bean(name ="directExchangeTwo" )
    public DirectExchange directExchangeTwo(){
        return new DirectExchange("directExchangeOrder");
    }
    //交换机与队列绑定
    @Bean
    public Binding directExchangeToQueueTwo(Queue queueTwo,DirectExchange directExchangeTwo){
        return BindingBuilder.bind(queueTwo).to(directExchangeTwo).with("replenishOrder.key");
    }

    //供应商批次供货订单
    @Bean(name = "queuePscOrderPIci")
    public Queue queuePiCi(){
        return new Queue("queuePscOrderPIci");
    }
    //创建交换机
    @Bean(name ="directExchangeOrderPiCi" )
    public DirectExchange directExchangePiCi(){
        return new DirectExchange("directExchangeOrderPiCi");
    }
    //交换机与队列绑定
    @Bean
    public Binding directExchangeToQueuePiCi(@Qualifier("queuePscOrderPIci") Queue queueThere, DirectExchange directExchangeOrderPiCi){
        return BindingBuilder.bind(queueThere).to(directExchangeOrderPiCi).with("replenishOrderPiCi.key");
    }

    //供应商批次供货订单2
    @Bean(name = "queuePiCiZhu")
    public Queue queuePiCiZhu(){
        return new Queue("queuePiCiZhu");
    }
    //创建交换机
    @Bean(name ="directExchangeOrderPiCiZhu" )
    public DirectExchange directExchangeOrderPiCiZhu(){
        return new DirectExchange("directExchangeOrderPiCiZhu");
    }
    //交换机与队列绑定
    @Bean
    public Binding directExchangeToQueuePiCiZhu( Queue queuePiCiZhu, DirectExchange directExchangeOrderPiCiZhu){
        return BindingBuilder.bind(queuePiCiZhu).to(directExchangeOrderPiCiZhu).with("replenishOrderPiCiZhu.key");
    }

}
